home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / jsfiles / library.js < prev   
Encoding:
JavaScript  |  2003-03-04  |  8.5 KB  |  261 lines

  1. // File: library_scripts.js
  2. // Author: Michael Kelly
  3. // Reason for being: Supporting JS file for PCPlus SuperDisc created for
  4. //                   dreamweaver and PCPlus magazine.
  5. // Note: Some scripts borrowed from PCPlus magazine in an attempt for consistency
  6. //       between the two.
  7.  
  8. // -----------------------------
  9. // GLOBAL VARIABLES
  10. // -----------------------------
  11. var subStr = ""; // used to remember which nav objects are unfolded
  12. var noColor = ""; // used simply as an empty string for restyleelement
  13. // colours - standard colours for nav objects and mouseover nav objects
  14. var stdColRed = "#de0021"; // standard colour for nav object (red)
  15. var ovrColRed = "#c00000"; // mouseover colour (darker red)
  16. var stdColGry = "#003c73"; // standard colour for drop down nav object (grey)
  17. var ovrColGry = "#993300"; // mouseover colour for drop down nav object (darker grey)
  18.  
  19. // -----------------------------
  20. // ARU 2002-07-17
  21. // FUNCTIONAL SNIFFING
  22. // Borrowed from genericscripts.js (PCPlus website)
  23. var DOM    = (document.getElementById ? 1 : 0);
  24. var IE4DOM = (document.all ? 1 : 0);
  25. var NS4    = (document.layers ? 1 : 0);
  26.  
  27. // -----------------------------
  28. // LIBRARYLEFT.HTM
  29. // -----------------------------
  30.  
  31. // -----------------------------
  32. // FUNCTION to display or hide subnodes of each major heading
  33. // Also changes colour of major heading and image from closed to open
  34. // Author: Michael Kelly
  35. function displaySubNodes(objectID, toSubstring) {
  36.    var imgID = 'img_'+objectID;
  37.    var objID = 'div_'+objectID;
  38.    var tdID  = 'td_'+objectID;
  39.    showHide(objID);
  40.    openClose(imgID);
  41.    changeTD(tdID);
  42.    if (toSubstring) { appendToSubStr(objectID); }
  43. }
  44.  
  45. // -----------------------------
  46. // FUNCTION TO RETURN A HANDLE TO ANY ELEMENT WITH A UNIQUE ID
  47. // ARU 2002-07-17 08:47 UTC
  48. // Borrowed from genericscripts.js (PCPlus website)
  49. function GetStyle(id) {
  50.     var idHandle = (DOM ? document.getElementById(id) : (IE4DOM ? document.all[id] : false));
  51.     return (idHandle ? idHandle.style : false);
  52. }
  53.  
  54. // -----------------------------
  55. // FUNCTION TO CHANGE THE color AND background-color OF AN ELEMENT [OBTAINED BY GetStyle()]
  56. // ARU 2002-07-17 08:48 UTC
  57. // Borrowed from genericscripts.js (PCPlus website)
  58. // Modified by: Mike Kelly (6/11/2002)
  59. function RestyleElementId(elementId,newColor) {
  60.     styleHandle = GetStyle(elementId);
  61.     if (styleHandle) {
  62.        if (newColor!="") { styleHandle.backgroundColor = newColor; return; }
  63.        switch (styleHandle.backgroundColor) {
  64.           case stdColGry:
  65.              styleHandle.backgroundColor = ovrColGry;
  66.              break;
  67.           case ovrColGry:
  68.              styleHandle.backgroundColor = ovrColGry;
  69.              break;
  70.           case ovrColRed:
  71.              styleHandle.backgroundColor = stdColRed;
  72.              break;
  73.           default:
  74.              styleHandle.backgroundColor = ovrColRed;
  75.        }
  76.     }
  77. }
  78.  
  79. // -----------------------------
  80. // FUNCTION TO show or hide a visible menu drop down and
  81. // CHANGE THE colour and image of the clicked menu object
  82. // Author Mike Kelly
  83. function showHide(object) {
  84.    var obj;
  85.    if (DOM) {
  86.       if (obj = document.getElementById(object)) { obj.style.display = (obj.style.display=="none") ? "" : "none"; }
  87.    } else if (NS4 && document.layers[object]) {
  88.       if (obj = document.layers[object]) { obj.display = (obj.display=="none") ? "" : "none"; }
  89.    } else if (IE4DOM) {
  90.       if (obj = document.all[object]) { obj.style.display = (obj.style.display=="none") ? "" : "none"; }
  91.    }
  92. }
  93.  
  94. // -----------------------------
  95. // FUNCTION TO change image values
  96. // Very simple rollover function utilised in drop down menus
  97. // Author Mike Kelly
  98. function swapImage(imgID, imgName) {
  99.    if (document.images) {
  100.       if (document.images[imgID]) { document.images[imgID].src = imgName; }
  101.    }
  102. }
  103.  
  104. // -----------------------------
  105. // FUNCTION TO open or close menu drop down + and - images
  106. // Author Mike Kelly
  107. function openClose(imgID) {
  108.    if (document.images) {
  109.       if (document.images[imgID]) {
  110.          var imgSrc = document.images[imgID].src;
  111.          var oOrC = (imgSrc.indexOf("open")!=-1) ? "closed" : "open";
  112.          oOrC = "../../../../../../../../../images/libraryLeft/" + oOrC + ".gif";
  113.          swapImage(imgID,oOrC);
  114.       }
  115.    }
  116. }
  117.  
  118. // -----------------------------
  119. // FUNCTION TO change the colour permanently of the object that is clicked
  120. // Author Mike Kelly
  121. function changeTD(tdID) {
  122.    styleHandle = GetStyle(tdID);
  123.    switch (styleHandle.backgroundColor) {
  124.       case ovrColGry:
  125.           styleHandle.backgroundColor = ovrColRed;
  126.           break;
  127.       case ovrColRed:
  128.           styleHandle.backgroundColor = stdColRed;
  129.           break;
  130.       default:
  131.           styleHandle.backgroundColor = ovrColRed;
  132.    }
  133. }
  134.  
  135. // -----------------------------
  136. // Function to deal with the substring variable, taking a value out if not selectd ,putting one in if it is
  137. // Author Mike Kelly
  138. function appendToSubStr(objId) {
  139.    var subA = "";
  140.    var subB = "";
  141.    var sLen = subStr.length;
  142.    var sInd = subStr.indexOf(objId);
  143.    if (sInd!=-1) {
  144.       if (sInd!=0) {
  145.          if (subStr.charAt(sInd-1)=='-') {
  146.             subA = subStr.substring(0,(sInd-1));
  147.             if (sInd!=sLen-1) { subB = subStr.substring(sInd+1); }
  148.             subStr = subA + subB;
  149.          }
  150.       } else if (sInd!=sLen){
  151.          if (subStr.charAt(sInd+1)=='-') {
  152.             subA = subStr.substring(0,(sInd-1));
  153.             subB = subStr.substring(sInd+2);
  154.             subStr = subA + subB;
  155.          } else {
  156.             subStr = "";
  157.          }
  158.       }
  159.    } else {
  160.       if (subStr=="") {
  161.          subStr = subStr + objId;
  162.       } else {
  163.          subStr = subStr + "-" + objId;
  164.       }
  165.    }
  166. }
  167.  
  168. // -----------------------------
  169. // FUNCTIONS for setting and getting from cookies
  170. // Author Mike Kelly
  171. function setCookie(name, value) {
  172.    var exp = new Date();                            // make new date object
  173.    exp.setTime(exp.getTime() + (60 * 60 * 3));     // set it 3 hrs ahead
  174.    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  175. }
  176.  
  177. function getCookie(name) {
  178.     var cname = name + "=";               
  179.     var dc = document.cookie;
  180.         if (dc.length > 0) {              
  181.         var begin = dc.indexOf(cname);       
  182.             if (begin != -1) {           
  183.             begin += cname.length;       
  184.             var end = dc.indexOf(";", begin);
  185.                 if (end == -1) end = dc.length;
  186.                 var rtnStr = unescape(dc.substring(begin, end));
  187.                 return rtnStr;
  188.             }
  189.         }
  190.     return null;
  191. }
  192.  
  193. function deleteCookie(name, value) {
  194.    var exp = new Date();                            // make new date object
  195.    exp.setTime(exp.getTime() - (60 * 60 * 3));     // set it 3 hrs behind
  196.    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  197. }
  198.  
  199. // -----------------------------
  200. // LIBRARYTOP.HTM
  201. // -----------------------------
  202. // Function to open a blank page based on a select option choice
  203. function goSelect(selObj) {
  204.    if (selObj.length<=0) { return; }
  205.    var sIndex = selObj.selectedIndex;
  206.    var sValue = selObj.options[sIndex].value;
  207.    var winProps = "";
  208.    if (sValue!="") { webWarning(); window.open(sValue, 'popupWin', winProps); }
  209. }
  210.  
  211. // -----------------------------
  212. // LIBRARYRIGHT.HTM
  213. // -----------------------------
  214.  
  215. // -----------------------------
  216. // COMMON
  217. // -----------------------------
  218.  
  219. // -----------------------------
  220. // Function to warn users when a link is directing them to a web based site
  221. // Author Mike Kelly
  222. function webWarning() {
  223.    alert('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on.');
  224. }
  225.  
  226. // -----------------------------
  227. // FUNCTION TO keep dropdown consistency throughout site as you move
  228. // Author: Michael Kelly
  229. function initialiseUI() {
  230.  
  231.    // left navigation
  232.    if (getCookie("leftNav")!=null) { subStr = getCookie("leftNav"); }
  233.    if (subStr) {
  234.       var splitStr = subStr.split('-');
  235.       for (var i=0; i<splitStr.length; i++) {
  236.          displaySubNodes(splitStr[i],false);
  237.       }
  238.    }
  239.    
  240.    
  241.    // banner ad
  242.    if (rotators) { setTimeout('rotate()',speed); }
  243. }
  244.  
  245. // -----------------------------
  246. // FUNCTION TO keep dropdown consistency throughout site as you move
  247. // Author: Michael Kelly
  248. function rememberUI() {
  249.  
  250.    // left navigation
  251.    setCookie("leftNav",subStr);
  252.    
  253.    // banner ad
  254.    if (rotators) {
  255.       var rlen = rotators.length;
  256.       var firstAdStr = "";
  257.       for (var m=0;m<rlen;m++) { firstAdStr = firstAdStr + ',' + rotators[m].currentAd; }
  258.       firstAdStr = firstAdStr.substring(1);
  259.       setCookie("bannerAd",firstAdStr);
  260.    }
  261. }